﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZJF.GenericTech._01_回顾List和Dictionary
{
    public class TestListDict
    {
        public void Test1() { 
            List<string> nameList = new List<string>() { 
                "张三",
                "李四",
                "王五"
            };

            Console.WriteLine($"nameList 一共有{nameList.Count}个元素");

            foreach (string name in nameList)
            {
                Console.WriteLine($"{name}");
            }

        }

        public void Test2()
        {
            List<int> nums = new List<int>();

            for (int i = 0; i < 10; i++) {
                nums.Add(i);
            }


            Console.WriteLine($"nums 中一共有{nums.Count}个元素");

            foreach (int i in nums)
            {
                Console.WriteLine(i);
            }


        }

        public void Test3() { 
            
            List<Student> students= new List<Student>() { 
                new Student(1, "张三", 18),
                new Student(2, "李四", 19),
                new Student(3, "王五", 20),
                new Student(4, "马六", 21)
            };

            Console.WriteLine($"总共有：{students.Count}位同学");

            foreach (Student student in students)
            {
                student.Info();
            }

        }

        public void Test4()
        {
            Dictionary<string, string> books = new Dictionary<string, string>() {
                { "罗贯中","《三国演义》"},
                { "施耐庵","《西游记》"},
                { "曹雪芹", "《红楼梦》"},
                { "吴承恩", "《水浒传》"}
            };

            Console.WriteLine($"一共有{books.Count}本书;");

            foreach (string author in books.Keys)
            {
                Console.WriteLine($"{author}:{books[author]}");
            }


        }
    }
}
